home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Paintgun.lua < prev    next >
Text File  |  2010-08-31  |  6KB  |  179 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Paintgun + Projectile Bullet
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.paintgun={}
  10. cc.paintgun.bullet={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.paintgun.gfx_wpn=loadgfx("weapons/paintgun.bmp")                        -- Weapon Image
  14. setmidhandle(cc.paintgun.gfx_wpn)
  15. cc.paintgun.gfx_pro=loadgfx("weapons/shot.bmp")                            -- Projectile Image
  16. setmidhandle(cc.paintgun.gfx_pro)
  17. cc.paintgun.sfx_attack=loadsfx("paintgun.ogg")                            -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: paintgun
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.paintgun.id=addweapon("cc.paintgun","Paintgun",cc.paintgun.gfx_wpn)    -- Add Weapon
  24. cc.paintgun.ammo=10                                                        -- 10 Bullets
  25.  
  26. function cc.paintgun.draw()                                                -- Draw
  27.     setblend(blend_alpha)
  28.     setalpha(1)
  29.     setcolor(255,255,255)
  30.     drawinhand(cc.paintgun.gfx_wpn,6,0)
  31.     -- HUD ammobar
  32.     if cc.paintgun.ammo-weapon_shots>0 then
  33.         hudammobar(cc.paintgun.ammo-weapon_shots,cc.paintgun.ammo)
  34.     end
  35.     -- HUD Crosshair
  36.     if cc.paintgun.ammo-weapon_shots>0 then
  37.         hudcrosshair(6,3)
  38.     end
  39. end
  40.  
  41. function cc.paintgun.attack(attack)                                -- Attack
  42.     -- Decrement timer
  43.     if weapon_timer>0 then
  44.         weapon_timer=weapon_timer-1
  45.     end
  46.     -- Attack
  47.     if weapon_shots<cc.paintgun.ammo and weapon_timer<=0 and attack==1 then
  48.         -- No more weapon switching!
  49.         useweapon(0)
  50.         -- Reset Timer
  51.         weapon_timer=15
  52.         -- Attack
  53.         playsound(cc.paintgun.sfx_attack)
  54.         weapon_shots=weapon_shots+1
  55.         id=createprojectile(cc.paintgun.bullet.id)
  56.         projectiles[id]={}
  57.         -- Ignore collision with current player at beginning
  58.         projectiles[id].ignore=playercurrent()
  59.         -- Set initial position of projectile
  60.         projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(getplayerrotation(0)))*5.0
  61.         projectiles[id].y=getplayery(0)+3+math.cos(math.rad(getplayerrotation(0)))*5.0
  62.         -- Set speed of projectile
  63.         projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*15.0
  64.         projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*15.0
  65.         -- Initial movement
  66.         projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
  67.         projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
  68.         for i=1,3,1 do
  69.             if cc.paintgun.bullet.move(id)==1 then
  70.                 break
  71.             end
  72.         end
  73.         -- Effects
  74.         recoil(2)
  75.         particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
  76.         particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
  77.         particlefadealpha(0.005)
  78.         -- End Turn
  79.         if (weapon_shots>=cc.paintgun.ammo) then
  80.             endturn()
  81.         end
  82.     end
  83. end
  84.  
  85. --------------------------------------------------------------------------------
  86. -- Projectile: Bullet
  87. --------------------------------------------------------------------------------
  88.  
  89. cc.paintgun.bullet.id=addprojectile("cc.paintgun.bullet")        -- Add Projectile
  90.  
  91. function cc.paintgun.bullet.draw(id)                            -- Draw
  92.     -- Setup draw mode
  93.     setblend(blend_light)
  94.     setalpha(1)
  95.     setcolor(255,255,0)
  96.     setscale(1,1)
  97.     -- Calculate projectile rotation
  98.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  99.     -- Draw projectile
  100.     drawimage(cc.paintgun.gfx_pro,projectiles[id].x,projectiles[id].y)
  101.     -- Draw Arrow if out of Screen
  102.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  103. end
  104.  
  105. function cc.paintgun.bullet.update(id)                            -- Update
  106.     -- Wind + Gravity influence on speed
  107.     projectiles[id].sx=projectiles[id].sx+getwind()*0.02
  108.     projectiles[id].sy=projectiles[id].sy+getgravity()
  109.     -- Move
  110.     cc.paintgun.bullet.move(id)
  111. end
  112.  
  113. function cc.paintgun.bullet.move(id)
  114.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  115.     -- Move (in substep loop for optimal collision precision)
  116.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  117.     msubx=projectiles[id].sx/msubt
  118.     msuby=projectiles[id].sy/msubt
  119.     for i=1,msubt,1 do
  120.         projectiles[id].x=projectiles[id].x+msubx
  121.         projectiles[id].y=projectiles[id].y+msuby        
  122.         -- Collision
  123.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)==1 then
  124.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  125.                 -- Cause damage
  126.                 if playercollision()~=0 and playercollision()~=projectiles[id].ignore then
  127.                     playerdamage(playercollision(),1)
  128.                 elseif objectcollision()>0 then
  129.                     objectdamage(objectcollision(),1)
  130.                 end
  131.                 -- Effects
  132.                 j=math.random(1,5)
  133.                 if j==1 then
  134.                     r=255; g=0; b=0
  135.                 elseif j==2 then
  136.                     r=0; g=255; b=0
  137.                 elseif j==3 then
  138.                     r=50; g=100; b=255
  139.                 elseif j==4 then
  140.                     r=200; g=0; b=255
  141.                 else
  142.                     r=255; g=255; b=0
  143.                 end
  144.                 j=math.random(1,3)
  145.                 x=projectiles[id].x+math.sin(math.rad(rot))*20
  146.                 y=projectiles[id].y-math.cos(math.rad(rot))*20
  147.                 if j==1 then terrainalphaimage(gfx_blood25,x+math.random(-5,5),y+math.random(-5,5),math.random(7,10)*0.1,r,g,b); playsound(sfx_splatter4) end
  148.                 if j==2 then terrainalphaimage(gfx_blood50,x+math.random(-7,7),y+math.random(-7,7),math.random(7,10)*0.1,r,g,b); playsound(sfx_splatter3) end
  149.                 if j==3 then terrainalphaimage(gfx_blood75,x+math.random(-10,10),y+math.random(-10,10),math.random(7,10)*0.1,r,g,b); playsound(sfx_splatter2) end
  150.                 for k=1,5 do
  151.                     particle(p_smoke,x,y)
  152.                     particlecolor(r,g,b)
  153.                     particlefadealpha(0.005)
  154.                     particle(p_blood,x,y)
  155.                     particlecolor(r,g,b)
  156.                     particlespeed(math.random(-10,10)*0.1,math.random(-10,10)*0.1)
  157.                 end
  158.                 -- Free projectile
  159.                 freeprojectile(id)
  160.                 return 1
  161.             end
  162.         else
  163.             projectiles[id].ignore=0
  164.         end
  165.         -- Water
  166.         if (projectiles[id].y)>getwatery()+5 then
  167.             -- Effects
  168.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  169.             if math.random(1,2)==1 then
  170.                 playsound(sfx_hitwater2)
  171.             else
  172.                 playsound(sfx_hitwater3)
  173.             end
  174.             -- Free projectile
  175.             freeprojectile(id)
  176.             return 1
  177.         end
  178.     end
  179. end